<?php
/**
 * JSON接口
 *
 * Created		: 2011-06-14
 * Modified		: 2011-07-06
 * @link		: http://www.qixbo.com
 * @copyright	: [Qixbo.Com] (c) 2011
 * @author		: Joseph Chen (jsph.chen@gmail.com)
 */
class JsonPhp
{
	
	private static $rawOutputData = null;
	
	public static function service($data=null)
	{
		if (empty($data)) {
			$data = App::getPostData();
		}
		if (empty($data['parameters'])) {
			$data['parameters'] = array();
		}
		$data = App::callService(
						$data['serviceName'], 
						$data['methodName'], 
						$data['parameters']
				);
		
		self::$rawOutputData = json_encode($data);
		return self::$rawOutputData;
	}
	
	public static function output($data=null)
	{
		if ($data) {
			if (is_string($data)) {
				echo $data;
			} else if (is_array($data) || is_object($data)) {
				echo json_encode($data);
			} else {
				echo '{"a":false, "b":"Unknow Error!"}';
			}
		} else {
			echo self::$rawOutputData;
		}
		exit;
	}
	
}
